<template>
<div class="product-add">
    <!--form表单-->
    <el-form size="small" ref="form" :model="form" label-width="250px">
      <!--小程序设置-->
      <div class="common-form">{{$t('appsetting.share_settings')}}</div>

      <el-form-item :label="$t('appsetting.share_landing_page')">
        <el-radio v-model="form.type" :label="1">{{$t('appsetting.public_or_h5')}}</el-radio>
        <el-radio v-model="form.type" :label="2">{{$t('appsetting.miniapp')}}</el-radio>
        <el-radio v-model="form.type" :label="3">{{$t('appsetting.download_page')}}</el-radio>
        <div class="tips">{{$t('appsetting.share_description')}}</div>
      </el-form-item>
      <template v-if="form.type == 1">
        <el-form-item :label="$t('appsetting.public_h5_path')">
          <el-input v-model="form.openSite" class="max-w460"></el-input>
          <div class="tips">{{$t('appsetting.default_deploy_note')}}</div>
        </el-form-item>
      </template>
      <template v-if="form.type == 2">
        <el-form-item :label="$t('appsetting.miniapp_original_id')">
          <el-input v-model="form.ghId" class="max-w460"></el-input>
          <div class="tips">{{$t('appsetting.miniapp_original_id_note')}}</div>
        </el-form-item>
        <el-form-item label="webUrl">
          <el-input v-model="form.webUrl" class="max-w460"></el-input>
          <div class="tips">{{$t('appsetting.miniapp_invalid_url')}}</div>
        </el-form-item>
      </template>
      <template v-if="form.type == 3">
        <el-form-item :label="$t('appsetting.app_download_url')">
          <el-input v-model="form.downUrl" class="max-w460"></el-input>
          <div class="tips">{{$t('appsetting.app_download_note')}}</div>
        </el-form-item>
        <el-form-item :label="$t('appsetting.relation_binding')">
          <el-radio v-model="form.bindType" :label="1">{{$t('appsetting.bind_direct')}}</el-radio>
          <el-radio v-model="form.bindType" :label="2">{{$t('appsetting.bind_after_auth')}}</el-radio>
          <div class="tips">{{$t('appsetting.bind_auth_note')}}</div>
        </el-form-item>
      </template>
      <!--提交-->
      <div class="common-button-wrapper">
          <el-button type="primary" @click="onSubmit">{{$t('appsetting.submit')}}</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
import AppSettingApi from '@/api/appsetting.js';
export default {
  data() {
    return {
      /*form表单数据*/
      form: {
        type: 1,
        openSite: '',
        ghId: '',
        webUrl: '',
        downUrl: '',
        bindType: 1
      }
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      let self = this;
      AppSettingApi.appshareDetail({}, true).then(res => {
        if (res.data != null) {
          self.form = res.data;
        }
      }).catch(error => {});
    },
    //提交表单
    onSubmit() {
      let self = this;
      let params = this.form;
      AppSettingApi.editAppShare(params, true).then(data => {
        ElMessage({
          message: $t("appsetting.setup_success"),
          type: 'success'
        });
      }).catch(error => {});
    }
  }
};
</script>

<style scoped>
.tips {
    color: #ccc;
  }
</style>

